/* 行走图颜色（色调、混合模式等）
* 
* 【事件标签/事件指令注释(冒号后可有空格)】
* 
* <Blendmode: x>
* 
* x：混合模式代码
* 0（正常）,1（叠加）,2（正片叠底）,3（滤色）
*
* 事件标签/事件指令注释(冒号后可有空格)
* 
* <Tone: red, green, blue, grey>
* 
* red, green, blue：红绿蓝（-255~255）
* gray：灰度（0~255）
* 数值设置参考事件指令里的【更改画面色调】或【更改图片色调】
* 
*/
var SWDA_CharacterColor = SWDA_CharacterColor || {};


SWDA_CharacterColor.Game_Event_setupPage = Game_Event.prototype.setupPage;
Game_Event.prototype.setupPage = function () {
    SWDA_CharacterColor.Game_Event_setupPage.call(this);

    this.setupCharacterColorNotetags();
    this.setupCharacterColorCommentTags();
};

Game_Event.prototype.setupCharacterColorNotetags = function () {
    if (this.event().note === '') return;
    if (this.event().note.match(/<Blendmode:\s*(\d+)>/i)) {
        this.setBlendMode(parseInt(RegExp.$1));
    }
    if (this.event().note.match(/<Tone:\s*(\-?\d+),\s*(\-?\d+),\s*(\-?\d+),\s*(\d+)>/i)) {
        this.setTone([parseInt(RegExp.$1),parseInt(RegExp.$2),parseInt(RegExp.$3),parseInt(RegExp.$4)]);
    }
    
};

Game_Event.prototype.setupCharacterColorCommentTags = function () {
    if (!this.page()) return;

    var list = this.list();
    var length = list.length;
    for (var i = 0; i < length; ++i) {
        var ev = list[i];
        if ([108, 408].contains(ev.code)) {
            if (ev.parameters[0].match(/<Blendmode:\s*(\d+)>/i)) {
                this.setBlendMode(parseInt(RegExp.$1));
            }
            if (ev.parameters[0].match(/<Tone:\s*(\-?\d+),\s*(\-?\d+),\s*(\-?\d+),\s*(\d+)>/i)) {
                this.setTone([parseInt(RegExp.$1),parseInt(RegExp.$2),parseInt(RegExp.$3),parseInt(RegExp.$4)]);
            }
        }
    }
};



Game_CharacterBase.prototype.setTone = function(tone) {
    this._tone = tone;
};

Game_CharacterBase.prototype.tone = function() {
    return this._tone;
};

SWDA_CharacterColor.Game_CharacterBase_InitMembers = Game_CharacterBase.prototype.initMembers;
Game_CharacterBase.prototype.initMembers = function() {
    SWDA_CharacterColor.Game_CharacterBase_InitMembers.call(this);
    this._tone = [0, 0, 0, 0];
};


SWDA_CharacterColor.Sprite_Character_UpdateOther = Sprite_Character.prototype.updateOther;
Sprite_Character.prototype.updateOther = function() {
    SWDA_CharacterColor.Sprite_Character_UpdateOther.call(this);
    this.setColorTone(this._character.tone());
};
